package com.yueshang.neuron.modular.system.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yueshang.neuron.common.util.Node;
import com.yueshang.neuron.modular.system.api.IDeptService;
import com.yueshang.neuron.modular.system.api.IRoleService;
import com.yueshang.neuron.modular.system.dao.mapper.DeptMapper;
import com.yueshang.neuron.modular.system.dao.mapper.RoleMapper;
import com.yueshang.neuron.modular.system.model.Role;
import com.yueshang.neuron.modular.system.vo.res.node.ZTreeNode;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * 部门具体实现处理service实现
 *
 * @author shililu
 * @since 2018-08-30 13:02:48
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper,Role> implements IRoleService {

    @Resource
    private RoleMapper roleMapper;

//    @Resource
//    private RelationMapper relationMapper;
//
//    @Override
//    @Transactional(readOnly = false)
//    public void setAuthority(Integer roleId, String ids) {
//
//        // 删除该角色所有的权限
//        this.roleMapper.deleteRolesById(roleId);
//
//        // 添加新的权限
//        for (Long id : Convert.toLongArray(true, Convert.toStrArray(",", ids))) {
//            Relation relation = new Relation();
//            relation.setRoleid(roleId);
//            relation.setMenuid(id);
//            this.relationMapper.insert(relation);
//        }
//    }

    @Override
    @Transactional(readOnly = false)
    public void delRoleById(Integer roleId) {
        //删除角色
        this.roleMapper.deleteById(roleId);

        // 删除该角色所有的权限
        this.roleMapper.deleteRolesById(roleId);
    }

    @Override
    public List<Map<String, Object>> selectRoles(String condition) {
        return this.baseMapper.selectRoles(condition);
    }

    @Override
    public int deleteRolesById(Integer roleId) {
        return this.baseMapper.deleteRolesById(roleId);
    }

    @Override
    public List<ZTreeNode> roleTreeList() {
        return this.baseMapper.roleTreeList();
    }

    @Override
    public List<ZTreeNode> roleTreeListByRoleId(String[] roleId) {
        return this.baseMapper.roleTreeListByRoleId(roleId);
    }

    @Override
    public List<Node> getNodeList(String condition) {
        return roleMapper.getNodeList(condition);
    }
}